﻿package  
{
	import flash.display.Sprite;
	import flash.display.StageQuality;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import events.AntSimulatorEvent;
	
	/**
	 * ...
	 * @author Daniel Sheldon
	 */
	public class AntSimulator extends Sprite
	{
		static public var _width:Number;
		static public var _height:Number;
		
		private static var _numOfAnts:int;
		public static var dispatcher:EventDispatcher = new EventDispatcher();
		
		public function AntSimulator(width:Number, height:Number) 
		{
			_width = width;
			_height = height;
			
			addEventListener(Event.ADDED_TO_STAGE, init);
			addEventListener(Event.ENTER_FRAME, update);
		}
		
		private function update(e:Event):void 
		{
			Ant.ground.bitmapData.unlock();
			Ant.ground.bitmapData.lock();
		}
		
		private function init(e:Event):void 
		{
			//stage.quality = StageQuality.LOW;
			
			var pt:PheromoneTrails = new PheromoneTrails(_width, _height);
			addChild(pt);
			
			Ant.ground = pt;
			
			addEventListener(MouseEvent.CLICK, addHill);
		}

		private function addHill (e:MouseEvent) 
		{
			var hill:Hill = new Hill(mouseX, mouseY, this);
			addChild(hill);
		}
		
		
		static public function get numOfAnts():int { return _numOfAnts; }
		
		static public function set numOfAnts(value:int):void 
		{
			_numOfAnts = value;
			var event:AntSimulatorEvent = new AntSimulatorEvent(AntSimulatorEvent.ANT_COUNT_CHANGE);
			dispatcher.dispatchEvent(event);
		}
	}
	
}